package com.example.demo.reflectstudy;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;

/**
 * @Description JavaFrame
 * @Author songchuanlong
 * @Date 2025-06-10
 */
public class JavaFrame {
    public static void saveContent(Object obj) throws Exception {
//        PrintStream ps = new PrintStream(new FileOutputStream("D:\\java\\practice20250413\\Thread\\demo\\src\\data.txt", true));
        PrintStream ps = new PrintStream(new FileOutputStream("src\\data.txt", true));
        Class c = obj.getClass();
        String cSimpleName = c.getSimpleName();
        ps.println("______"+cSimpleName+"_________");
        Field[] fileds = c.getDeclaredFields();
        for (Field field : fileds) {

            field.setAccessible(true);//私有变量，禁止检查访问控制
            String name = field.getName();
            String value = field.get(obj) + "";
            ps.println(name+":"+value);
        }
    }
}
